define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'identify/index' + location.search,
                    add_url: 'identify/add',
                    edit_url: 'identify/edit',
                    del_url: 'identify/del',
                    multi_url: 'identify/multi',
                    import_url: 'identify/import',
                    table: 'identify',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'identify_data.name', title: __('名称'), operate: 'LIKE'},

                        {
                            field: 'url', title: __('图片'), operate: false, events: Table.api.events.image, formatter: function (value, row, index) {
                                value = value == null || value.length === 0 ? '' : value.toString();
                                value = value ? value : '/assets/addons/cms/img/noimage.png';
                                var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
                                return '<a href="javascript:"><img class="' + classname + '" src="' + Fast.api.cdnurl(value) + '" /></a>';
                            }
                        },


                        {
                            field: 'createtime',
                            title: __('Createtime'),
                     
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime,
                            autocomplete: false
                        },

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
